package my.ts.code.adapter;

import java.util.ArrayList;

import my.ts.code.objects.Service;
import my.ts.code.viewgroup.ServiceItem;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ServiceAdapter extends ArrayAdapter<Service> {

	ArrayList<Service> myArray;
	int res;
	Context context;

	public ServiceAdapter(Context context, int textViewResourceId,
			ArrayList<Service> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub

		this.context = context;
		res = textViewResourceId;
		myArray = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// // TODO Auto-generated method stub
		View itemview = convertView;
		if (itemview == null) {
			itemview = new ServiceItem(getContext());
		}

		final Service service = myArray.get(position);
		if (service != null) {
			TextView tvName = ((ServiceItem) itemview).title;
			tvName.setText(service.getTitle());

			ImageView img = ((ServiceItem) itemview).image;
			if (service.getAvatar() != null)
				img.setBackgroundDrawable(service.getAvatar());
		}
		return itemview;
	}

}
